import { IPSModelSortable } from '../../ipsmodel-sortable';
import { IPSCodeList } from '../../codelist/ipscode-list';
import { IPSDataEntity } from '../ipsdata-entity';
import { IPSDEFGroup } from '../defield/ipsdefgroup';
import { IPSDEField } from '../defield/ipsdefield';
import { IPSDERAggData } from '../der/ipsderagg-data';
import { IPSDEDataQuery } from './ipsdedata-query';
import { IPSDEDataSet } from './ipsdedata-set';
import { IPSDEDataSetGroupParam } from './ipsdedata-set-group-param';
import { IPSDEDataSetInput } from './ipsdedata-set-input';
import { IPSDEDataSetParam } from './ipsdedata-set-param';
import { IPSDEDataSetReturn } from './ipsdedata-set-return';
import { IPSDELogic } from '../logic/ipsdelogic';
import { IPSDEOPPriv } from '../priv/ipsdeoppriv';
import { IPSSysPFPlugin } from '../../res/ipssys-pfplugin';
import { IPSSysSFPlugin } from '../../res/ipssys-sfplugin';
import { IPSSysUserDR } from '../../security/ipssys-user-dr';
import { IPSSubSysServiceAPIDEMethod } from '../../service/ipssub-sys-service-apidemethod';
import { PSModelObjectImpl } from '../../psmodel-object-impl';

export class PSDEDataSetImpl extends PSModelObjectImpl implements IPSDEDataSet, IPSModelSortable {
  get actionHolder(): 1 | 2 | 3 {
    return this.M.actionHolder != null ? this.M.actionHolder : 3;
  }

  protected activedatapsdelogic: IPSDELogic | null = null;

  getActiveDataPSDELogic(): IPSDELogic | null {
    if (this.activedatapsdelogic != null) return this.activedatapsdelogic;
    const value = this.M.getActiveDataPSDELogic;
    if (value == null) {
      return null;
    }
    const ipsdataentity = this.getParentPSModelObject('dataentity.IPSDataEntity') as IPSDataEntity;
    if (ipsdataentity != null) {
      this.activedatapsdelogic = ipsdataentity.findPSDELogic(value);
    }
    return this.activedatapsdelogic;
  }

  get activeDataPSDELogic(): IPSDELogic | null {
    return this.getActiveDataPSDELogic();
  }

  getActiveDataPSDELogicMust(): IPSDELogic {
    const value = this.getActiveDataPSDELogic();
    if (value == null) {
      throw new Error('未指定当前数据转换逻辑');
    }
    return value;
  }

  get cacheScope(): 'GLOBAL' | 'ORG' | 'USER' {
    return this.M.cacheScope;
  }

  get cacheTimeout(): number {
    return this.M.cacheTimeout != null ? this.M.cacheTimeout : -1;
  }

  get codeName(): string {
    return this.M.codeName;
  }

  get customDRMode2Param(): string {
    return this.M.customDRMode2Param;
  }

  get customDRModeParam(): string {
    return this.M.customDRModeParam;
  }

  get dataSetTag(): string {
    return this.M.dataSetTag;
  }

  get dataSetTag2(): string {
    return this.M.dataSetTag2;
  }

  get dataSetTag3(): string {
    return this.M.dataSetTag3;
  }

  get dataSetTag4(): string {
    return this.M.dataSetTag4;
  }

  get dataSetType(): 'DATAQUERY' | 'INDEXDE' | 'MULTIFORM' | 'CODELIST' | 'DELOGIC' | 'SCRIPT' | 'REMOTE' {
    return this.M.dataSetType || 'DATAQUERY';
  }

  get dynaModelFilePath(): string {
    return this.M.dynaModelFilePath;
  }

  get extendMode(): 0 | 2 {
    return this.M.extendMode != null ? this.M.extendMode : 0;
  }

  get groupMode(): 0 | 1 | 2 {
    return this.M.groupMode != null ? this.M.groupMode : 0;
  }

  get logicName(): string {
    return this.M.logicName;
  }

  get majorSortDir(): 'ASC' | 'DESC' {
    return this.M.majorSortDir;
  }

  protected majorsortpsdefield: IPSDEField | null = null;

  getMajorSortPSDEField(): IPSDEField | null {
    if (this.majorsortpsdefield != null) return this.majorsortpsdefield;
    const value = this.M.getMajorSortPSDEField;
    if (value == null) {
      return null;
    }
    const ipsdataentity = this.getParentPSModelObject('dataentity.IPSDataEntity') as IPSDataEntity;
    if (ipsdataentity != null) {
      this.majorsortpsdefield = ipsdataentity.findPSDEField(value);
    }
    return this.majorsortpsdefield;
  }

  get majorSortPSDEField(): IPSDEField | null {
    return this.getMajorSortPSDEField();
  }

  getMajorSortPSDEFieldMust(): IPSDEField {
    const value = this.getMajorSortPSDEField();
    if (value == null) {
      throw new Error('未指定默认主排序属性');
    }
    return value;
  }

  get memo(): string {
    return this.M.memo;
  }

  get minorSortDir(): 'ASC' | 'DESC' {
    return this.M.minorSortDir;
  }

  protected minorsortpsdefield: IPSDEField | null = null;

  getMinorSortPSDEField(): IPSDEField | null {
    if (this.minorsortpsdefield != null) return this.minorsortpsdefield;
    const value = this.M.getMinorSortPSDEField;
    if (value == null) {
      return null;
    }
    const ipsdataentity = this.getParentPSModelObject('dataentity.IPSDataEntity') as IPSDataEntity;
    if (ipsdataentity != null) {
      this.minorsortpsdefield = ipsdataentity.findPSDEField(value);
    }
    return this.minorsortpsdefield;
  }

  get minorSortPSDEField(): IPSDEField | null {
    return this.getMinorSortPSDEField();
  }

  getMinorSortPSDEFieldMust(): IPSDEField {
    const value = this.getMinorSortPSDEField();
    if (value == null) {
      throw new Error('未指定默认从排序属性');
    }
    return value;
  }

  get name(): string {
    return this.M.name;
  }

  get orderValue(): number {
    return this.M.orderValue != null ? this.M.orderValue : 99999;
  }

  get orgDR(): 1 | 2 | 4 | 8 {
    return this.M.orgDR != null ? this.M.orgDR : 0;
  }

  get pOTime(): number {
    return this.M.pOTime != null ? this.M.pOTime : -1;
  }

  protected pscodelist: IPSCodeList | null = null;

  getPSCodeList(): IPSCodeList | null {
    if (this.pscodelist != null) return this.pscodelist;
    const value = this.M.getPSCodeList;
    if (value == null) {
      return null;
    }
    this.pscodelist = this.getPSModel4('codelist.IPSCodeList', value, 'getPSCodeList') as IPSCodeList;
    return this.pscodelist;
  }

  get psCodeList(): IPSCodeList | null {
    return this.getPSCodeList();
  }

  getPSCodeListMust(): IPSCodeList {
    const value = this.getPSCodeList();
    if (value == null) {
      throw new Error('未指定代码表对象');
    }
    return value;
  }

  protected psdedataqueries: IPSDEDataQuery[] | null = null;

  getPSDEDataQueries(): IPSDEDataQuery[] | null {
    if (this.psdedataqueries == null) {
      const value = this.M.getPSDEDataQueries;
      if (value == null) {
        return null;
      }
      const arrayNode: any[] = value;
      if (arrayNode.length == 0) {
        return null;
      }
      const list: IPSDEDataQuery[] = [];
      const ipsdataentity = this.getParentPSModelObject('dataentity.IPSDataEntity') as IPSDataEntity;
      for (let i = 0; i < arrayNode.length; i++) {
        const item = ipsdataentity.findPSDEDataQuery(arrayNode[i]);
        if (item != null) {
          list.push(item);
        }
      }
      this.psdedataqueries = list;
    }
    return this.psdedataqueries.length == 0 ? null : this.psdedataqueries;
  }

  get psDEDataQueries(): IPSDEDataQuery[] | null {
    return this.getPSDEDataQueries();
  }

  findPSDEDataQuery(objKey: any): IPSDEDataQuery | null {
    return this.getPSModel5('dataentity.ds.IPSDEDataQuery', this.getPSDEDataQueries(), objKey) as IPSDEDataQuery;
  }

  protected psdedatasetgroupparams: IPSDEDataSetGroupParam[] | null = null;

  getPSDEDataSetGroupParams(): IPSDEDataSetGroupParam[] | null {
    if (this.psdedatasetgroupparams == null) {
      this.psdedatasetgroupparams = this.fillChildListModel(this.M.getPSDEDataSetGroupParams, 'dataentity.ds.IPSDEDataSetGroupParam') as IPSDEDataSetGroupParam[];
    }
    return this.psdedatasetgroupparams;
  }

  get psDEDataSetGroupParams(): IPSDEDataSetGroupParam[] | null {
    return this.getPSDEDataSetGroupParams();
  }

  findPSDEDataSetGroupParam(objKey: any): IPSDEDataSetGroupParam | null {
    return this.getPSModel5('dataentity.ds.IPSDEDataSetGroupParam', this.getPSDEDataSetGroupParams(), objKey) as IPSDEDataSetGroupParam;
  }

  protected psdedatasetinput: IPSDEDataSetInput | null = null;

  getPSDEDataSetInput(): IPSDEDataSetInput | null {
    if (this.psdedatasetinput != null) return this.psdedatasetinput;
    const value = this.M.getPSDEDataSetInput;
    if (value == null) {
      return null;
    }
    this.psdedatasetinput = this.getPSModel4('dataentity.ds.IPSDEDataSetInput', value, 'getPSDEDataSetInput') as IPSDEDataSetInput;
    return this.psdedatasetinput;
  }

  get psDEDataSetInput(): IPSDEDataSetInput | null {
    return this.getPSDEDataSetInput();
  }

  getPSDEDataSetInputMust(): IPSDEDataSetInput {
    const value = this.getPSDEDataSetInput();
    if (value == null) {
      throw new Error('未指定调用输入对象');
    }
    return value;
  }

  protected psdedatasetparams: IPSDEDataSetParam[] | null = null;

  getPSDEDataSetParams(): IPSDEDataSetParam[] | null {
    if (this.psdedatasetparams == null) {
      this.psdedatasetparams = this.fillChildListModel(this.M.getPSDEDataSetParams, 'dataentity.ds.IPSDEDataSetParam') as IPSDEDataSetParam[];
    }
    return this.psdedatasetparams;
  }

  get psDEDataSetParams(): IPSDEDataSetParam[] | null {
    return this.getPSDEDataSetParams();
  }

  findPSDEDataSetParam(objKey: any): IPSDEDataSetParam | null {
    return this.getPSModel5('dataentity.ds.IPSDEDataSetParam', this.getPSDEDataSetParams(), objKey) as IPSDEDataSetParam;
  }

  protected psdedatasetreturn: IPSDEDataSetReturn | null = null;

  getPSDEDataSetReturn(): IPSDEDataSetReturn | null {
    if (this.psdedatasetreturn != null) return this.psdedatasetreturn;
    const value = this.M.getPSDEDataSetReturn;
    if (value == null) {
      return null;
    }
    this.psdedatasetreturn = this.getPSModel4('dataentity.ds.IPSDEDataSetReturn', value, 'getPSDEDataSetReturn') as IPSDEDataSetReturn;
    return this.psdedatasetreturn;
  }

  get psDEDataSetReturn(): IPSDEDataSetReturn | null {
    return this.getPSDEDataSetReturn();
  }

  getPSDEDataSetReturnMust(): IPSDEDataSetReturn {
    const value = this.getPSDEDataSetReturn();
    if (value == null) {
      throw new Error('未指定调用返回对象');
    }
    return value;
  }

  protected psdefgroup: IPSDEFGroup | null = null;

  getPSDEFGroup(): IPSDEFGroup | null {
    if (this.psdefgroup != null) return this.psdefgroup;
    const value = this.M.getPSDEFGroup;
    if (value == null) {
      return null;
    }
    const ipsdataentity = this.getParentPSModelObject('dataentity.IPSDataEntity') as IPSDataEntity;
    if (ipsdataentity != null) {
      this.psdefgroup = ipsdataentity.findPSDEFGroup(value);
    }
    return this.psdefgroup;
  }

  get psDEFGroup(): IPSDEFGroup | null {
    return this.getPSDEFGroup();
  }

  getPSDEFGroupMust(): IPSDEFGroup {
    const value = this.getPSDEFGroup();
    if (value == null) {
      throw new Error('未指定属性组对象');
    }
    return value;
  }

  protected psdelogic: IPSDELogic | null = null;

  getPSDELogic(): IPSDELogic | null {
    if (this.psdelogic != null) return this.psdelogic;
    const value = this.M.getPSDELogic;
    if (value == null) {
      return null;
    }
    const ipsdataentity = this.getParentPSModelObject('dataentity.IPSDataEntity') as IPSDataEntity;
    if (ipsdataentity != null) {
      this.psdelogic = ipsdataentity.findPSDELogic(value);
    }
    return this.psdelogic;
  }

  get psDELogic(): IPSDELogic | null {
    return this.getPSDELogic();
  }

  getPSDELogicMust(): IPSDELogic {
    const value = this.getPSDELogic();
    if (value == null) {
      throw new Error('未指定实体处理逻辑');
    }
    return value;
  }

  protected psdeoppriv: IPSDEOPPriv | null = null;

  getPSDEOPPriv(): IPSDEOPPriv | null {
    if (this.psdeoppriv != null) return this.psdeoppriv;
    const value = this.M.getPSDEOPPriv;
    if (value == null) {
      return null;
    }
    this.psdeoppriv = this.getPSModel4('dataentity.priv.IPSDEOPPriv', value, 'getPSDEOPPriv') as IPSDEOPPriv;
    return this.psdeoppriv;
  }

  get psDEOPPriv(): IPSDEOPPriv | null {
    return this.getPSDEOPPriv();
  }

  getPSDEOPPrivMust(): IPSDEOPPriv {
    const value = this.getPSDEOPPriv();
    if (value == null) {
      throw new Error('未指定服务访问操作标识');
    }
    return value;
  }

  protected psderaggdata: IPSDERAggData | null = null;

  getPSDERAggData(): IPSDERAggData | null {
    if (this.psderaggdata != null) return this.psderaggdata;
    const value = this.M.getPSDERAggData;
    if (value == null) {
      return null;
    }
    const ipsdataentity = this.getParentPSModelObject('dataentity.IPSDataEntity') as IPSDataEntity;
    if (ipsdataentity != null) {
      this.psderaggdata = ipsdataentity.findMajorPSDERBase(value) as IPSDERAggData;
    }
    return this.psderaggdata;
  }

  get psDERAggData(): IPSDERAggData | null {
    return this.getPSDERAggData();
  }

  getPSDERAggDataMust(): IPSDERAggData {
    const value = this.getPSDERAggData();
    if (value == null) {
      throw new Error('未指定聚合数据关系');
    }
    return value;
  }

  protected pssubsysserviceapidemethod: IPSSubSysServiceAPIDEMethod | null = null;

  getPSSubSysServiceAPIDEMethod(): IPSSubSysServiceAPIDEMethod | null {
    if (this.pssubsysserviceapidemethod != null) return this.pssubsysserviceapidemethod;
    const value = this.M.getPSSubSysServiceAPIDEMethod;
    if (value == null) {
      return null;
    }
    const ipsdataentity = this.getParentPSModelObject('dataentity.IPSDataEntity') as IPSDataEntity;
    if (ipsdataentity != null) {
      this.pssubsysserviceapidemethod = ipsdataentity.getPSSubSysServiceAPIDEMust().findPSSubSysServiceAPIDEMethod(value);
    }
    return this.pssubsysserviceapidemethod;
  }

  get psSubSysServiceAPIDEMethod(): IPSSubSysServiceAPIDEMethod | null {
    return this.getPSSubSysServiceAPIDEMethod();
  }

  getPSSubSysServiceAPIDEMethodMust(): IPSSubSysServiceAPIDEMethod {
    const value = this.getPSSubSysServiceAPIDEMethod();
    if (value == null) {
      throw new Error('未指定子系统实体接口方法');
    }
    return value;
  }

  protected pssyspfplugin: IPSSysPFPlugin | null = null;

  getPSSysPFPlugin(): IPSSysPFPlugin | null {
    if (this.pssyspfplugin != null) return this.pssyspfplugin;
    const value = this.M.getPSSysPFPlugin;
    if (value == null) {
      return null;
    }
    this.pssyspfplugin = this.getPSModel4('res.IPSSysPFPlugin', value, 'getPSSysPFPlugin') as IPSSysPFPlugin;
    return this.pssyspfplugin;
  }

  get psSysPFPlugin(): IPSSysPFPlugin | null {
    return this.getPSSysPFPlugin();
  }

  getPSSysPFPluginMust(): IPSSysPFPlugin {
    const value = this.getPSSysPFPlugin();
    if (value == null) {
      throw new Error('未指定前端扩展插件');
    }
    return value;
  }

  protected pssyssfplugin: IPSSysSFPlugin | null = null;

  getPSSysSFPlugin(): IPSSysSFPlugin | null {
    if (this.pssyssfplugin != null) return this.pssyssfplugin;
    const value = this.M.getPSSysSFPlugin;
    if (value == null) {
      return null;
    }
    this.pssyssfplugin = this.getPSModel4('res.IPSSysSFPlugin', value, 'getPSSysSFPlugin') as IPSSysSFPlugin;
    return this.pssyssfplugin;
  }

  get psSysSFPlugin(): IPSSysSFPlugin | null {
    return this.getPSSysSFPlugin();
  }

  getPSSysSFPluginMust(): IPSSysSFPlugin {
    const value = this.getPSSysSFPlugin();
    if (value == null) {
      throw new Error('未指定后端扩展插件');
    }
    return value;
  }

  protected pssysuserdr: IPSSysUserDR | null = null;

  getPSSysUserDR(): IPSSysUserDR | null {
    if (this.pssysuserdr != null) return this.pssysuserdr;
    const value = this.M.getPSSysUserDR;
    if (value == null) {
      return null;
    }
    this.pssysuserdr = this.getPSModel4('security.IPSSysUserDR', value, 'getPSSysUserDR') as IPSSysUserDR;
    return this.pssysuserdr;
  }

  get psSysUserDR(): IPSSysUserDR | null {
    return this.getPSSysUserDR();
  }

  getPSSysUserDRMust(): IPSSysUserDR {
    const value = this.getPSSysUserDR();
    if (value == null) {
      throw new Error('未指定用户数据范围对象');
    }
    return value;
  }

  protected pssysuserdr2: IPSSysUserDR | null = null;

  getPSSysUserDR2(): IPSSysUserDR | null {
    if (this.pssysuserdr2 != null) return this.pssysuserdr2;
    const value = this.M.getPSSysUserDR2;
    if (value == null) {
      return null;
    }
    this.pssysuserdr2 = this.getPSModel4('security.IPSSysUserDR', value, 'getPSSysUserDR2') as IPSSysUserDR;
    return this.pssysuserdr2;
  }

  get psSysUserDR2(): IPSSysUserDR | null {
    return this.getPSSysUserDR2();
  }

  getPSSysUserDR2Must(): IPSSysUserDR {
    const value = this.getPSSysUserDR2();
    if (value == null) {
      throw new Error('未指定用户数据范围对象2');
    }
    return value;
  }

  get pageSize(): number {
    return this.M.pageSize != null ? this.M.pageSize : -1;
  }

  get paramMode(): 1 | 2 {
    return this.M.paramMode != null ? this.M.paramMode : 1;
  }

  get predefinedType(): 'CODELIST' | 'INDEXDE' | 'MULTIFORM' | 'DELOGIC' | 'SCRIPT' | 'REMOTE' {
    return this.M.predefinedType;
  }

  get scriptCode(): string {
    return this.M.scriptCode;
  }

  get secBC(): string {
    return this.M.secBC;
  }

  get secDR(): 1 | 2 | 4 | 8 {
    return this.M.secDR != null ? this.M.secDR : 0;
  }

  get userCat(): string {
    return this.M.userCat;
  }

  get userTag(): string {
    return this.M.userTag;
  }

  get userTag2(): string {
    return this.M.userTag2;
  }

  get userTag3(): string {
    return this.M.userTag3;
  }

  get userTag4(): string {
    return this.M.userTag4;
  }

  get viewLevel(): -1 | 0 | 1 | 2 | 3 | 100 {
    return this.M.viewLevel != null ? this.M.viewLevel : -1;
  }

  get customParam(): boolean {
    return this.M.customParam != null ? this.M.customParam : false;
  }

  get defaultMode(): boolean {
    return this.M.defaultMode != null ? this.M.defaultMode : false;
  }

  get enableAudit(): boolean {
    return this.M.enableAudit != null ? this.M.enableAudit : false;
  }

  get enableBackend(): boolean {
    return this.M.enableBackend;
  }

  get enableCache(): boolean {
    return this.M.enableCache != null ? this.M.enableCache : false;
  }

  get enableFront(): boolean {
    return this.M.enableFront;
  }

  get enableGroup(): boolean {
    return this.M.enableGroup != null ? this.M.enableGroup : false;
  }

  get enableOrgDR(): boolean {
    return this.M.enableOrgDR != null ? this.M.enableOrgDR : false;
  }

  get enableSecBC(): boolean {
    return this.M.enableSecBC != null ? this.M.enableSecBC : false;
  }

  get enableSecDR(): boolean {
    return this.M.enableSecDR != null ? this.M.enableSecDR : false;
  }

  get enableTempData(): boolean {
    return this.M.enableTempData != null ? this.M.enableTempData : false;
  }

  get enableUserDR(): boolean {
    return this.M.enableUserDR != null ? this.M.enableUserDR : false;
  }

  get valid(): boolean {
    return this.M.valid != null ? this.M.valid : true;
  }

  get cls(): string {
    return 'PSDEDataSetImpl';
  }

  instanceof(cls: string): boolean {
    if (cls == 'IPSModelSortable' || cls == 'dataentity.ds.IPSDEDataSet') return true;
    return super.instanceof(cls);
  }
}
